//
//  YZXEmoticoPackModel.swift
//  表情键盘
//
//  Created by 叶周翔 on 16/7/29.
//  Copyright © 2016年 叶周翔. All rights reserved.
//

import UIKit

class YZXEmoticoPackModel: NSObject {
    /// 表情包文件夹名称
    var id: String?
    /// 表情包名称
    var group_name_cn: String?

    /// 表情包的模型
    var emoticons: [YZXEmoticonModel]
    
    /// 拆分成多个页面
    var allPageEmoji: [[YZXEmoticonModel]] = [[YZXEmoticonModel]]()
    
    init(id: String, group_name_cn: String, emoticons:[YZXEmoticonModel]){
        self.id = id
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
        super.init()
        // 将表情包拆分成多页
        self.spliEmojitcons()
    }
    
    private func spliEmojitcons() {
        /// 计算总共有几页
        let pageCount = (emoticons.count + emojiPage - 1) / emojiPage
        
        if pageCount == 0{
            let pageEmoji = [YZXEmoticonModel]()
            allPageEmoji.append(pageEmoji)
        }
        
        for i in 0..<pageCount{
            let location = i * emojiPage
            var length = emojiPage
            if location + length > emoticons.count {
                
                length = emoticons.count - location
            }
            let range = NSRange(location: location, length: length)
            
            let pageEmoticons = (emoticons as NSArray).subarrayWithRange(range) as! [YZXEmoticonModel]
            allPageEmoji.append(pageEmoticons)
            
        }
        
        
    }
    
    
    
}
